package conf2;

import conf2.iface.IMenuListener;
import conf2.ui.MainWindow;
import java.io.IOException;
import javax.swing.JOptionPane;

public class MenuListener implements IMenuListener {

    private final MainWindow mw;
    private final Configuration config;
    private GameStarter starter;

    MenuListener(MainWindow mw, Configuration config) {
        this.mw = mw;
        this.config = config;
    }

    void setGameStarter(GameStarter s) {
        starter = s;
    }

    public void gameAsServer() {
        starter.startServerGame();
    }

    public void gameAsClient() {
        starter.startClientGame();
    }

    public void gameExit() {
        try {
            config.save(Configuration.getProperFilePath());
        } catch (IOException ie) {
            JOptionPane.showMessageDialog(mw, "Could not save configuration file.");
        }
        System.exit(0);
    }

    public void helpAbout() {
        JOptionPane.showMessageDialog(mw, "Hej");
    }

    public void popup(boolean selected) {
        config.setPopup(selected);
    }

    public void sound(boolean isOn) {
        config.setSound(isOn);
    }

    public void specialCardReminder(boolean selected) {
        config.setSpecialCardReminder(selected);
    }

    public void useHighlight(boolean selected) {
        config.setMovementAssist(selected);
    }
}
